<!--<script>    
    jQuery(document).ready(function(){
        jQuery("#adminform").validationEngine('attach', {promptPosition : "bottomRight"});
    });
</script>-->
<script language="javascript">
	jQuery(document).ready(function(){
		$('#ParentID').change(function(){
			var catid = $('#ParentID').val() ;
			$.post(url+"product/get_level", {'catid':catid}, function(data){
				$('#level').val(parseInt(data)+1) ;
			});
		});
	});
</script>
<?=form_open('product/addcat/',array('id'=>'adminform'));?>

<input type="hidden" id="level" name="level" value="" />
<table class="form">
   <tr>
      <td class="w150 required label">Tên danh mục</td>
      <td><input type="text" name="CategoryName" id="title" class="w300" value="<?=set_value('CategoryName')?>"></td>
   </tr>
   <tr>
      <td class="label">Danh mục</td>
      <td><select name="ParentID" id="ParentID">
            <option value="0">Là danh mục gốc</option>
            <? foreach($listmaincat as $cat):
						$listsub1 = $this->product->check_parentid($cat->CategoryID);
			   ?>
            <option value="<?=$cat->CategoryID?>">
            <?=$cat->CategoryName?>
            </option>
            <? if(count($listsub1) > 0){?>
            <? foreach($listsub1 as $sub1): ?>
            <option value="<?=$sub1->CategoryID?>">¦&nbsp;
            <?=$cat->CategoryName?>
            &nbsp;¦&nbsp;
            <?=$sub1->CategoryName?>
            </option>
            <? 
					// level 3
					$listsub2 = $this->product->check_parentid($sub1->CategoryID);
					if(count($listsub2) > 0){
						foreach($listsub2 as $sub2):
							echo '<option value="'.$sub2->CategoryID.'">¦&nbsp;&nbsp;'.$cat->CategoryName.' ¦ '.$sub1->CategoryName.' ¦ '.$sub2->CategoryName.'</option>' ;
						endforeach ;
					} // end level 3
				?>
            <? endforeach?>
            <? }?>
            <?endforeach;?>
         </select></td>
   </tr>
   <tr>
      <td class="label">Trang chủ</td>
      <td><input type="checkbox" name="IsMainMenu" value="1" checked="checked" /></td>
   </tr>
   <tr>
      <td class="label">Kích hoạt</td>
      <td><input type="checkbox" name="bl_active" value="1" checked="checked" /></td>
   </tr>
   <tr>
      <td></td>
      <td class="footer"><input type="submit" name="bt_submit" class="themmoi" /></td>
   </tr>
</table>
<?=form_close();?>
